import Cache from '../comm/cache'

const ACCESS_TOKEN = 'ACCESS_TOKEN'
const CURRENT_USER = 'CURRENT_USER'
const LAST_LOGIN_TIME = 'LAST_LOGIN_TIME'
const APPLICATION_DATA = 'APPLICATION_DATA'
const NAVIGATE_DATA = 'NAVIGATE_DATA'
const CURRENT_VOTE_COLUMN = 'CURRENT_VOTE_COLUMN'

export function saveAccessToken(value) {
  Cache.save(ACCESS_TOKEN, value)
}

export function getAccessToken() {
  return Cache.get(ACCESS_TOKEN)
}

export function saveCurrentUser(value) {
  Cache.save(CURRENT_USER, JSON.stringify(value))
}

export function getCurrentUser() {
  let value = Cache.get(CURRENT_USER)
  return value ? JSON.parse(value) : null
}

export function saveLastLoginTime(value) {
  Cache.save(LAST_LOGIN_TIME, value)
}

export function getLastLoginTime() {
  return Cache.get(LAST_LOGIN_TIME)
}

export function saveApplicationData(value) {
  Cache.save(APPLICATION_DATA, JSON.stringify(value))
}

export function getApplicationData() {
  let value = Cache.get(APPLICATION_DATA)
  return value ? JSON.parse(value) : []
}

export function saveNavigateData(value) {
  Cache.save(NAVIGATE_DATA, JSON.stringify(value))
}

export function getNavigateData() {
  let value = Cache.get(NAVIGATE_DATA)
  return value ? JSON.parse(value) : []
}

export function saveCurrentVoteColumn(value) {
  Cache.save(CURRENT_VOTE_COLUMN, JSON.stringify(value))
}

export function getCurrentVoteColumn() {
  let value = Cache.get(CURRENT_VOTE_COLUMN)
  return value ? JSON.parse(value) : []
}
